/*
 * @Author: szx
 * @Date: 2022-02-25 14:44:07
 * @LastEditTime: 2022-02-25 14:46:51
 * @Description:
 * @FilePath: \leetcode\300-399\383\383_2.js
 */
/**
 * @param {string} ransomNote
 * @param {string} magazine
 * @return {boolean}
 */
var canConstruct = function (ransomNote, magazine) {
    if (ransomNote.length > magazine.length) return false;
    const arr = new Array(26).fill(0);

    for (let i = 0; i < magazine.length; i++) arr[magazine.charCodeAt(i) - 97]++;
    for (let i of ransomNote) {
        arr[i.charCodeAt() - 97]--;
        if (arr[i.charCodeAt() - 97] < 0) return false;
    }
    return true;
};
